package com.ebay.model;
import com.ebay.util.DBconn;
import com.opensymphony.*;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import java.util.*;
import java.sql.*;

public class sellPageSetmodel extends ActionSupport {
Map session=ActionContext.getContext().getSession();;
private int category_id,subcategory_id,a;
private String category_name,subcategory_name;
public String rslt,rslt1;
Connection con;
Statement stmt,stmt2;
private String query;
DBconn db;


public int getCategory_id() {
	System.out.println("contresult"+(Integer) session.get("cat_id"));
	return (category_id=(Integer) session.get("cat_id"));
}
public int getSubcategory_id() {
	System.out.println("contresult"+(Integer) session.get("sub_catid"));
	return (subcategory_id=(Integer) session.get("sub_catid"));
}
public String getCategory_name() {
	return category_name;
}
public String getSubcategory_name() {
	return subcategory_name;
}
public String execute(){
	//session=ActionContext.getContext().getSession();
	try {
		db =new DBconn();
		con=db.getConnection();
		stmt=con.createStatement();
		
		ResultSet rs=stmt.executeQuery("select category_name from category where category_id='"+session.get("category_id")+"'");
	    rs.next();
	    category_name=rs.getString("category_name");
	    stmt2=con.createStatement();
	    ResultSet rs1=stmt2.executeQuery("select subcategory_name from subcategory where category_id='"+session.get("category_id")+"' and subcategory_id='"+session.get("subcategory_id")+"' ");
	    rs1.next();
	    subcategory_name=rs1.getString("subcategory_name");
	    session.put("category_name",category_name);
	    session.put("subcategory_name",subcategory_name);
	    if(category_name.equals("books"))
	    	rslt="booklist";
	    else
	        rslt=category_name+subcategory_name;
	    rslt1=category_name+">>>"+subcategory_name;
	    session.put("catnames", rslt1);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		System.out.println("error is"+e.getMessage());
		e.printStackTrace();
	}
	System.out.println("contresult"+rslt);
	return rslt;
}
}
